package com.maggroup.conference_system.controller;

import com.maggroup.conference_system.common.InfoPage;
import com.maggroup.conference_system.common.PageInfo;
import com.maggroup.conference_system.entity.Question;
import com.maggroup.conference_system.service.QuestionService;
import com.maggroup.conference_system.service.TextAnalyzeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/question")
public class QuestionController {
	
	
	@Autowired
	private QuestionService questionService;
	
	@Autowired
	private TextAnalyzeService textAnalyzeService;

	
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/page",method = RequestMethod.POST)
	public InfoPage<Question> page(@RequestBody Question question){
		Map<String, Object> properties = question.getProperties();
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageSize(Integer.parseInt(properties.get("pageSize").toString()));
		pageInfo.setPageNumber(Integer.parseInt(properties.get("pageNumber").toString()));
		Map<String, Object> sortMap = (Map<String, Object>) properties.get("sortMap");
		Map<String, Object> queryMap = (Map<String, Object>) properties.get("queryMap");
		pageInfo.setSortMap(sortMap);
		InfoPage<Question> questionPage = questionService.getQuestionPage(queryMap,pageInfo);
		return questionPage;
	}

	//切换是否忽略
	@RequestMapping(value = "/ignore", method = RequestMethod.PUT)
	public void ignore(@RequestBody Question question) {
		questionService.ignore(question);
	}

	@RequestMapping(value = "/", method = RequestMethod.POST)
	public Question create(@RequestBody Question question) {
		question.setTime(new Date());
		Question newQuestion = questionService.add(question);
		return newQuestion;

	}
	
	@RequestMapping(value = "/analysis",method= RequestMethod.GET)
	public List<String> analysis(@RequestParam(name = "meetingId") Integer meetingId){
		List<String> hotwords = textAnalyzeService.getHotWords(meetingId);
		return hotwords;
	}
}
